-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: make gate counting functions less confusing and avoid estimations #9046
Conversation
Changes to circuit sizes
🧾 Summary (100% most significant diffs)
Full diff report 👇
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you change the .hbs files that are used to generate these? Otherwise they will be rolled back next time we generate our code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be done
@@ -142,23 +142,15 @@ UltraWithKeccakVerifier UltraComposer::create_ultra_with_keccak_verifier(Circuit | |||
return output_state; | |||
} | |||
|
|||
size_t UltraComposer::compute_dyadic_circuit_size(CircuitBuilder& circuit) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redundant, could just call the builder functions that do the exact same thing
// Construct Honk proof | ||
Prover prover{ builder }; | ||
init_bn254_crs(prover.proving_key->proving_key.circuit_size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
core change: avoiding a needless builder computation just to get an incorrect srs size...
@@ -701,7 +697,8 @@ template <typename Builder = UltraCircuitBuilder> void gateCount(const std::stri | |||
for (auto constraint_system : constraint_systems) { | |||
auto builder = acir_format::create_circuit<Builder>( | |||
constraint_system, 0, {}, honk_recursion, std::make_shared<bb::ECCOpQueue>(), true); | |||
builder.finalize_circuit(); | |||
builder.finalize_circuit(/*ensure_nonzero=*/true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
core change: fix thats needed to properly add in the ensure nonzero gates
void AcirComposer::create_circuit(acir_format::AcirFormat& constraint_system, | ||
WitnessVector const& witness, | ||
bool collect_gates_per_opcode) | ||
void AcirComposer::create_finalized_circuit(acir_format::AcirFormat& constraint_system, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
core change: finalizing the circuit here
@@ -32,13 +32,23 @@ class AcirComposer { | |||
bool verify_proof(std::vector<uint8_t> const& proof); | |||
|
|||
std::string get_solidity_verifier(); | |||
size_t get_total_circuit_size() { return builder_.get_total_circuit_size(); }; | |||
size_t get_dyadic_circuit_size() { return builder_.get_circuit_subgroup_size(builder_.get_total_circuit_size()); }; | |||
size_t get_finalized_total_circuit_size() { return builder_.get_finalized_total_circuit_size(); }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
two new functions that give a finalized size (and check that the circuit is actually finalized)
barretenberg/cpp/src/barretenberg/dsl/acir_proofs/acir_composer.hpp
Outdated
Show resolved
Hide resolved
auto total_with_extra_gates = builder.get_total_circuit_size() + num_extra_gates; | ||
*total = htonl((uint32_t)total_with_extra_gates); | ||
*subgroup = htonl((uint32_t)builder.get_circuit_subgroup_size(builder.get_total_circuit_size())); | ||
builder.finalize_circuit(/*ensure_nonzero=*/true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we just overestimate if we ever have to pick. This function is used by plonk and honk, so we just go with adding more gates
barretenberg/cpp/src/barretenberg/smt_verification/circuit/standard_circuit.hpp
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just a few minor notes
barretenberg/cpp/src/barretenberg/circuit_checker/ultra_circuit_checker.cpp
Outdated
Show resolved
Hide resolved
barretenberg/cpp/src/barretenberg/ultra_honk/decider_proving_key.cpp
Outdated
Show resolved
Hide resolved
barretenberg/cpp/src/barretenberg/ultra_honk/decider_proving_key.hpp
Outdated
Show resolved
Hide resolved
…col/aztec-packages into lx/fix-finalize-circuit-calls
Removes unnecessary gate counting in Honk flows in main.cpp and instead inits the SRS based on the actual finalized gate count taken from the Prover.
Renames get_num_gates to get_estimated_num_finalized_gates, renames a few other functions to add "estimated" to their names to reflect their actual functionality and avoid misuse.
Replace estimating functions used in main.cpp and in c_bind.cpp with functions that return the actual finalized gate count.
Fixes a bug in an earlier PR #9042, which forgot the ensure_nonzero = true argument to finalize_circuit(), and undercounted the number of gates in the circuit, leading a smaller than needed SRS.